﻿package mortal.game.view.drugBack
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.events.*;
    import com.mui.utils.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.pack.*;
    import mortal.game.view.pack.data.*;
    import mortal.game.view.shopMall.data.*;
    import mortal.game.view.systemSetting.*;
    import mortal.game.view.vip.panel.*;
    import mortal.game.view.wizard.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class DrugPackModule extends BaseWindow
    {
        private var _packTabData:Array;
        private var _goodsData:Array;
        public var _tabBar:GTabarNew;
        private var _drugItemList:GTileList;
        private var _goodsList:GTileList;
        private var _leftNum:GTextFiled;
        private var _autoUse:GCheckBox;
        private var _vipOpenTips:VipOpenTipsPanel;

        public function DrugPackModule(param1:ILayer = null)
        {
            this._packTabData = Language.getArray(30500);
            super(param1);
            this.init();
            this.title = Language.getString(35290);
            return;
        }// end function

        private function init() : void
        {
            setSize(250, 360);
            this._goodsData = [[110021000, 110021001], [110031000, 111030001], [110131000, 110131001]];
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(8, 62, 240, 150, this, ImagesConst.PanelBg));
            this.pushUIToDisposeVec(UIFactory.bg(8, 216, 240, 120, this, ImagesConst.PanelBg));
            this._tabBar = UIFactory.gTabBarNew(2, 32, this._packTabData, 250, 473, 65, 26, this, this.tabBarChangeHandler, "TabButtonNew");
            this._tabBar.selectedIndex = -1;
            this._leftNum = UIFactory.gTextField("", 17, 65, 220, 20, this, null, true);
            this._leftNum.name = "drugPack_leftNum";
            this._drugItemList = UIFactory.tileList(13, 87, 230, 322, this);
            this._drugItemList.rowHeight = 46;
            this._drugItemList.columnWidth = 46;
            this._drugItemList.horizontalGap = 0;
            this._drugItemList.verticalGap = 0;
            this._drugItemList.setStyle("cellRenderer", PackCellRenderer);
            this._goodsList = UIFactory.tileList(15, 223, 250, 322, this);
            this._goodsList.rowHeight = 105;
            this._goodsList.columnWidth = 230;
            this._goodsList.horizontalGap = 10;
            this._goodsList.verticalGap = 5;
            this._goodsList.setStyle("cellRenderer", DrugItemCellRenderer);
            this._goodsList.isClickedUpdate = false;
            this._goodsList.isChangeUpdate = false;
            this._autoUse = UIFactory.checkBox(Language.getString(30505), 15, 185, 200, 28, null);
            this._autoUse.configEventListener(Event.CHANGE, this.setAutoUseDrug);
            this._vipOpenTips = UICompomentPool.getUICompoment(VipOpenTipsPanel);
            this._vipOpenTips.valueType = VipOpenTipsPanel.percentValue;
            this._vipOpenTips.resetValueTextPos(206, 9, 222, 9);
            this._vipOpenTips.resetLevelTextPos(73, 9, 77, 9);
            this._vipOpenTips.resetTipsTextPos(16, 8, 2, 6);
            this._vipOpenTips.move(7, 175);
            this.addChild(this._vipOpenTips);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._leftNum.name = "";
            this._tabBar.dispose(param1);
            this._tabBar = null;
            this._drugItemList.dispose(param1);
            this._drugItemList = null;
            this._goodsList.dispose(param1);
            this._goodsList = null;
            this._leftNum.dispose(param1);
            this._leftNum = null;
            this._autoUse.dispose(param1);
            this._autoUse = null;
            this._vipOpenTips.dispose(param1);
            this._vipOpenTips = null;
            super.disposeImpl(param1);
            return;
        }// end function

        public function changeTabIndex(param1:int) : void
        {
            this._tabBar.selectedIndex = param1;
            this.tabBarChangeHandler();
            return;
        }// end function

        public function refreshItem() : void
        {
            this._drugItemList.dataProvider = this.getDataProviderByIndex(this._tabBar.selectedIndex);
            return;
        }// end function

        public function refreshDrugNum() : void
        {
            switch(this._tabBar.selectedIndex)
            {
                case 0:
                {
                    this._leftNum.htmlText = Language.getString(30501) + " <font color=\'#42e554\'>" + Cache.instance.DrugPack.liftData.leftNum + "</font>";
                    break;
                }
                case 1:
                {
                    this._leftNum.htmlText = Language.getString(30502) + " <font color=\'#42e554\'>" + Cache.instance.DrugPack.manaData.leftNum + "</font>";
                    break;
                }
                case 2:
                {
                    this._leftNum.htmlText = Language.getString(30503) + " <font color=\'#42e554\'>" + Cache.instance.DrugPack.petLiftData.leftNum + "</font>";
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function updateVipTipsByType(param1:int) : void
        {
            this._vipOpenTips.vipType = param1;
            return;
        }// end function

        private function tabBarChangeHandler(event:MuiEvent = null) : void
        {
            this._drugItemList.dataProvider = this.getDataProviderByIndex(this._tabBar.selectedIndex);
            this._goodsList.dataProvider = this.getGoodsDataProvider(this._tabBar.selectedIndex);
            this.getClientValue();
            if (this._tabBar.selectedIndex == 0)
            {
                this.updateVipTipsByType(EVipRecordType._EVipRecordTypeDrugLife);
            }
            else if (this._tabBar.selectedIndex == 1)
            {
                this.updateVipTipsByType(EVipRecordType._EVipRecordTypeDrugMana);
            }
            return;
        }// end function

        private function getGoodsDataProvider(param1:int) : DataProvider
        {
            var _loc_6:ShopItemData = null;
            var _loc_2:* = new DataProvider();
            var _loc_3:* = this._goodsData[param1];
            var _loc_4:int = 1;
            var _loc_5:int = 0;
            while (_loc_5 < _loc_4)
            {
                
                _loc_6 = ShopConfig.instance.getFastBuyItemByCode(_loc_3[_loc_5]);
                _loc_2.addItem(_loc_6);
                _loc_5++;
            }
            return _loc_2;
        }// end function

        private function getDataProviderByIndex(param1:int) : DataProvider
        {
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:Object = null;
            var _loc_2:* = new DataProvider();
            switch(this._tabBar.selectedIndex)
            {
                case 0:
                {
                    this._leftNum.htmlText = Language.getString(30501) + " <font color=\'#42e554\'>" + Cache.instance.DrugPack.liftData.leftNum + "</font>";
                    _loc_3 = Cache.instance.pack.backPackCache.getItemsByGroupCategoryAndType(EGroup._EGroupProp, EProp._EPropDrug, EDrug._EDrugLifeBag);
                    break;
                }
                case 1:
                {
                    this._leftNum.htmlText = Language.getString(30502) + " <font color=\'#42e554\'>" + Cache.instance.DrugPack.manaData.leftNum + "</font>";
                    _loc_3 = Cache.instance.pack.backPackCache.getItemsByGroupCategoryAndType(EGroup._EGroupProp, EProp._EPropDrug, EDrug._EDrugManaBag);
                    break;
                }
                case 2:
                {
                    this._leftNum.htmlText = Language.getString(30503) + " <font color=\'#42e554\'>" + Cache.instance.DrugPack.petLiftData.leftNum + "</font>";
                    _loc_3 = Cache.instance.pack.backPackCache.getItemsByGroupCategoryAndType(EGroup._EGroupProp, EProp._EPropDrug, EDrug._EDrugPetLifeBag);
                    break;
                }
                default:
                {
                    break;
                }
            }
            if (_loc_3)
            {
                _loc_4 = 10;
                _loc_5 = 0;
                while (_loc_5 < _loc_4)
                {
                    
                    _loc_6 = this.getDataObjectByItemData(_loc_3[_loc_5]);
                    _loc_2.addItem(_loc_6);
                    _loc_5++;
                }
            }
            return _loc_2;
        }// end function

        private function getDataObjectByItemData(param1:ItemData) : PackObject
        {
            var _loc_2:* = new PackObject();
            if (param1)
            {
                _loc_2.itemData = param1;
            }
            return _loc_2;
        }// end function

        public function getClientValue() : void
        {
            switch(this._tabBar.selectedIndex)
            {
                case 0:
                {
                    this._autoUse.selected = ClientSetting.local.getIsDone(IsDoneType.AutoUseLifeDrug);
                    break;
                }
                case 1:
                {
                    this._autoUse.selected = ClientSetting.local.getIsDone(IsDoneType.AutoUseManaDrug);
                    break;
                }
                case 2:
                {
                    this._autoUse.selected = ClientSetting.local.getIsDone(IsDoneType.AutoUsePetLifeDrug);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function setAutoUseDrug(event:Event) : void
        {
            switch(this._tabBar.selectedIndex)
            {
                case 0:
                {
                    ClientSetting.local.setIsDone(this._autoUse.selected, IsDoneType.AutoUseLifeDrug);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.AutoUseDrugItem, EDrug._EDrugLifeBag));
                    break;
                }
                case 1:
                {
                    ClientSetting.local.setIsDone(this._autoUse.selected, IsDoneType.AutoUseManaDrug);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.AutoUseDrugItem, EDrug._EDrugManaBag));
                    break;
                }
                case 2:
                {
                    ClientSetting.local.setIsDone(this._autoUse.selected, IsDoneType.AutoUsePetLifeDrug);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.AutoUseDrugItem, EDrug._EDrugPetLifeBag));
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

    }
}
